package com.cattsoft.util.web;


import java.io.*; 
import javax.servlet.*; 

public class CharacterCodeFilter implements Filter {

	private String encoding = null;
	
	public void setEncoding(String encoding){
		this.encoding = encoding;
	}
	
 
	
    public CharacterCodeFilter() { 
    } 
    
    /** 
     * destroy 
     * 
     * @todo Implement this javax.servlet.Filter method 
     */ 
    public void destroy() { 
    } 

    /** 
     * doFilter 
     * 
     * @param servletRequest ServletRequest 
     * @param servletResponse ServletResponse 
     * @param filterChain FilterChain 
     * @throws IOException 
     * @throws ServletException 
     * @todo Implement this javax.servlet.Filter method 
     */ 
    public void doFilter(ServletRequest request, 
                         ServletResponse response, 
                         FilterChain chain) throws IOException, 
            ServletException { 
        try{
        	request.setCharacterEncoding(this.encoding);
            chain.doFilter(request, response); 
        }catch(Exception ex){ 
            ex.printStackTrace(); 
        }
    } 

    /** 
     * init 
     * 
     * @param filterConfig FilterConfig 
     * @throws ServletException 
     * @todo Implement this javax.servlet.Filter method 
     */ 
    public void init(FilterConfig filterConfig) throws ServletException { 
    	this.encoding = filterConfig.getInitParameter("encoding");
    } 
    
} 